<template>
    <div class="main-con systemUser">
        <!-- 搜索框 -->
        <div class="search-con">
            <div class="search-item">
                <div class="search-item-title">登录账号</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.accountNo" placeholder="请输入登录账号" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">用户名称</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.userName" placeholder="请输入用户名称" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">联系方式</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.telPhone" placeholder="请输入联系方式"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">角色</div>
                <div class="search-item-input">
                    <el-select size="mini" v-model="formData.role" placeholder="请选择角色">
                        <el-option v-for="item in roleOptions" :key="item.id" :label="item.roleName" :value="item.id">
                        </el-option>
                    </el-select>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title"></div>
                <el-button size="mini" type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button>
                <el-button size="mini" type="primary" icon="el-icon-delete" @click="handleClear">清空</el-button>
            </div>
        </div>

        <!-- 表格数据 -->
        <div class="table-con" v-loading="loading">
            <el-table :data="tableData" size="mini" :header-cell-style="{background:'#f8f8f8'}" style="width: 100%">
                <el-table-column type="index" label="序号" width="50" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="accountNo" label="登录账号" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="userName" label="用户名称" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="telPhone" label="联系方式" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="roleDesc" label="角色" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="email" label="邮箱" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column label="账号类型" width="" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <span>{{scope.row.roleType == 'system' ? '系统账号':'商家账号'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
            </el-table>
        </div>

        <!-- 表格分页 -->
        <div class="pagination-con">
            <m-pagination :currentPage="formData.pageNum" :pageSize="formData.pageSize" :total="total"
                @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange">
            </m-pagination>
        </div>
    </div>
</template>

<script>
import {
    querySystemUserInfo,
    queryAllRoleInfo
} from "@/common/service/systemManagement/systemUser.js";
import mPagination from "@/components/m-pagination/m-pagination";
export default {
    name: "systemUser",
    data() {
        return {
            // 搜索条件
            formData: {
                accountNo: "", //登录账号
                userName: "", //用户名称
                telPhone: "", //联系方式
                role: "", //角色
                pageNum: 1,
                pageSize: 10
            },
            roleOptions: [], //角色下拉框数据
            //表格数据
            tableData: [], //表格信息
            total: null, //表格总条数
            loading: false //表格加载动画
        };
    },
    created() {
        //初始化表格数据
        this._querySystemUserInfo();
        //初始化所有的角色
        this._queryAllRoleInfo();
    },
    methods: {
        /*----------------------------查询操作----------------------------*/
        //查询系统用户信息表格数据
        _querySystemUserInfo() {
            this.loading = true;
            querySystemUserInfo(this.formData)
                .then(res => {
                    this.loading = false;
                    this.tableData = res.content;
                    this.total = res.totalElements;
                })
                .catch(err => {
                    this.loading = false;
                    this.$message.error(err.message);
                });
        },
        //页码切换
        handleCurrentChange(val) {
            this.formData.pageNum = val;
            this._querySystemUserInfo();
        },
        //每页展示条数的切换
        handleSizeChange(val) {
            this.formData.pageSize = val;
            this._querySystemUserInfo();
        },
        //点击查询
        handleSearch() {
            this.formData.pageNum = 1;
            this.formData.pageSize = 10;
            this._querySystemUserInfo();
        },
        //点击清空
        handleClear() {
            this.formData = {
                accountNo: "",
                userName: "",
                telPhone: "",
                role: "",
                pageNum: 1,
                pageSize: 10
            };
            this.$message({
                type: "success",
                message: "清空成功!"
            });
            this._querySystemUserInfo();
        },
        //查询所有的角色信息
        _queryAllRoleInfo() {
            var data = {
                type: "1"
            };
            queryAllRoleInfo(data)
                .then(res => {
                    this.roleOptions = res;
                })
                .catch(err => {
                    this.$message.error(err.message);
                });
        }
    },
    components: {
        "m-pagination": mPagination
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.table-con {
    margin-top: 10px;
}
</style>